home *** CD-ROM | disk | FTP | other *** search
- /* fwrite.c, from p. 439 of Turbo C Bible */
- #include <stdio.h>
- char buffer[80] = "Testing fwirte\n\This is the second line.\n";
- main()
- {
- int numwrite;
- FILE *infile;
- char filename[80];
- printf("Enter name of a file to write to: ");
- gets(filename);
- /* Open the file for writing */
- if ((infile = fopen(filename, "wb")) == NULL)
- {
- printf("fopen failed.\n");
- exit(0);
- }
- /* Write 80 characters and display the */
- /* buffer */
- numwrite = fwrite((void *)buffer, sizeof(char), 80, infile);
- printf("%d characters written to file %s\n", numwrite, filename);
- printf("use 'TYPE %s' to see if it worked\n", filename);
- }